/**
 * SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
 * SPDX-License-Identifier: Mulan PSL v2
 */
/**
 * Created by czh on 2019/5/16.
 */

import * as TYPES from '../mutation_types';
import {VERSION_TYPE_MAP} from 'src/home/mod_common/const/authorization';
import urlAdapter from 'src/home/mod_common/url_adapter';
import Vue from 'vue';

const MOCK_MOCK_AUTH_INFO_URL = urlAdapter('license/queryLicenseInfo');

let state = {
    isShowAuthWarn: false,
    expireFlag: false,
    expireDays: '',
    expireTime: ''
};

let getters = {
    versionTypeText: (state) => {
        return VERSION_TYPE_MAP[~~state.expireFlag];
    }
};

let mutations = {
    [TYPES.TOGGLE_AUTH_WARN] (state, isShow) {
        state.isShowAuthWarn = isShow;
    },

    [TYPES.UPDATE_LICENSE] (state, data) {

        Object.assign(state, data);
    }

};
let actions = {

    // 获取序列号授权情况
    async ajaxFetchAuthInfo (context) {
        let that = Vue.prototype;
        let jsonData = await that.$ajax.get(MOCK_MOCK_AUTH_INFO_URL);
        if (!jsonData.success || !jsonData.data) {
            return that.$showErr(jsonData.message);
        }
        context.commit(TYPES.UPDATE_LICENSE, jsonData.data);
    }
};

export default {
    state,
    getters,
    mutations,
    actions
};
